import org.openqa.selenium.By;

import java.io.IOException;

/**
 * @projectName: The-examination-questionnaire-pass-test
 * @package: PACKAGE_NAME
 * @className: ProjectPage
 * @author: Tongxinxin
 * @description: 项目界面功能测试
 * @date: 2025/9/22 0:31
 * @version: 1.0
 */
public class ProjectPage extends  Util{
    public ProjectPage(String url) {
        super(url);
    }
    public static String url="http://8.155.1.153:8081/project";
    //未登录状态下进入首页
    public void NoLoginProject() throws IOException {
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.top___1C1Zi > div.header___5xZ3f > span"));

        //判断是否返回登录页面
        String expect=driver.getTitle();

        getScreenShot(getClass().getName());
        assert expect.equals("问卷考试系统");
    }

    //创建“问卷调查”
    public void LoginProjectQe() throws InterruptedException, IOException {
        //进行登录
        driver.findElement(By.cssSelector("#username")).sendKeys("tong");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button > span")).click();

        //点击我的项目
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(2) > span > a > div > span.anticon.ant-pro-base-menu-item-icon > span > svg")).click();
        //点击创建“问卷调查”
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button > span:nth-child(2)")).click();
        Thread.sleep(1000);
        // 根据文本内容定位
        driver.findElement(By.xpath("//ul/li/span[text()='问卷调查']")).click();
        ///html/body/div[5]/div/div/ul/li[1]/span

        //点击保存
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span")).click();
        Thread.sleep(1000);
        //返回我的项目
        driver.findElement(By.cssSelector("#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button")).click();
        //截图
        getScreenShot(getClass().getName());
        Thread.sleep(2000);

        //测试查询功能
        //在查询框中输入要查询的项目名称
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input")).sendKeys("请输入标题");
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button > span > svg")).click();
        //添加屏幕截图
        getScreenShot(getClass().getName());
        Thread.sleep(2000);

        //检查是否创建成功
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-list.ant-list-split.ant-list-grid.survey-home-content > div > div > div > div:nth-child(1) > div > div > div > div > div > div.card-header > span.survey-title"));
        String el=driver.getTitle();

        getScreenShot(getClass().getName());
        assert el.equals("请输入标题");

    }

    //创建“问卷调查”
    public void LoginProjectEx() throws InterruptedException, IOException, IOException {
        //进行登录
        driver.findElement(By.cssSelector("#username")).sendKeys("tong");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button > span")).click();

        //将页面放大
        driver.manage().window().fullscreen();
        //点击我的项目
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(2) > span > a > div > span.anticon.ant-pro-base-menu-item-icon > span > svg")).click();
        //点击创建“在线考试”
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button > span:nth-child(2)")).click();
        Thread.sleep(1000);
        // 根据文本内容定位
        driver.findElement(By.xpath("//ul/li/span[text()='在线考试']")).click();
        ///html/body/div[5]/div/div/ul/li[1]/span

        //点击保存
        driver.findElement(By.cssSelector("#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm > span")).click();
        Thread.sleep(1000);
        //返回我的项目
        driver.findElement(By.cssSelector("#root > div > div.survey-main-navigator > div.actions-container > div:nth-child(7) > a > button > span.anticon.anticon-home > svg")).click();
        //截图
        getScreenShot(getClass().getName());
        Thread.sleep(2000);

        //测试查询功能
        //在查询框中输入要查询的项目名称
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input")).sendKeys("考试名称");
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button > span > svg")).click();
        //添加屏幕截图
        getScreenShot(getClass().getName());
        Thread.sleep(2000);

        //检查是否创建成功
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-list.ant-list-split.ant-list-grid.survey-home-content > div > div > div > div:nth-child(1) > div > div > div > div > div > div.card-header > span.survey-title"));
        String el=driver.getTitle();

        getScreenShot(getClass().getName());
        assert el.equals("考试名称");

    }
}
